package org.wak.inventory
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.wak.action.IInteractable;
	import org.wak.action.actions.AdventureActions;
	import org.wak.main.AdventureMaster;

	/**
	 * This class represents an item in the Inventory.  
	 * 
	 */	
	public class InventoryItem extends Sprite implements IInteractable
	{
		// the inventory item id.
		protected var mItemId:String = "";
		// the inventory item id.
		protected var mItemName:String = "";
		// the inventory item display to show in the inventory.
		protected var mItemDisplay:Sprite = null;
		// the inventory item icon to show in the mouse pointer.
		protected var mItemMouseIcon:DisplayObject = null ;
		
		// copy of the item display to show in the buttons panel on SCI gui.
		protected var mItemPanelIconCopy:Sprite = null ;
		
		// local reference to the resource manager
		protected var mResources:Class = null;
		
		protected var mUnitaryUse:Boolean = false ;
		
		protected var mDescription:String = "" ;
		
		/**
		 * Constructor 
		 * @param pDef Definition of the inventory item
		 * 
		 */		
		public function InventoryItem(pDef:IInventoryItemDefinition)
		{
			super();
			mResources = AdventureMaster.Resources ;
			
			mItemId = pDef.itemId ;
			mItemName = pDef.itemName ;
			mItemDisplay = new Sprite();
			mItemDisplay.addChild( new mResources[pDef.itemDisplayId] );
			
			mItemPanelIconCopy = new Sprite();
			mItemPanelIconCopy.addChild( new mResources[pDef.itemDisplayId] );
			 
			mUnitaryUse = pDef.unitaryUse ;
			mDescription = pDef.description ;
			
			if(pDef.mouseIconDisplayId != "" )
			{
				mItemMouseIcon = new mResources[pDef.mouseIconDisplayId] ;
				mItemMouseIcon.x = pDef.mouseIconX ;
				mItemMouseIcon.y = pDef.mouseIconY ;
			}
			
			
				
			//trace(mItemId + " is unitary: "+ mUnitaryUse)
		}
		
		
		/**
		 * The DisplayObject which represents this item on the interface. 
		 * @return Sprite
		 * 
		 */		
		public function get itemDisplay():Sprite
		{
			return mItemDisplay ;
		}
		
		/**
		 * The DisplayObject which represents this item on the interface on SCI gui. 
		 * @return Sprite
		 * 
		 */		
		public function get guiItemDisplay():Sprite
		{
			return mItemPanelIconCopy ;
		}
		
		/**
		 * The DisplayObject icon which represents this item on the interface. 
		 * @return DisplayObject
		 * 
		 */		
		public function get itemIconDisplay():DisplayObject
		{
			return mItemMouseIcon ;
		}
		
		/**
		 * @inheritDoc 
		 */		
		public function get interactableId():String 
		{
			return mItemId ;	
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get interactionName():String 
		{
			return mItemName ;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get unitaryUse():Boolean 
		{
			return mUnitaryUse ;
		}
		
		public function set unitaryUse(value:Boolean):void 
		{
			mUnitaryUse = value;	
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get description():String 
		{
			return mDescription ;
		}
		
		/**
		 * @inheritDoc 
		 */	
		public function get defaultAction():String 
		{
			return AdventureActions.ActionIdLookAt ;
		}
		
		
	}
}